package pta.newch04.ex21;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(" ");
        int[] arr = new int[input.length];
        for (int i = 0; i < input.length; i++) {
            arr[i] = Integer.parseInt(input[i]);
        }
        for (int num : arr) {
            System.out.println(num);
        }
        int maxIndex = 0;
        int minIndex = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] > arr[maxIndex]){
                maxIndex = i;
            }
            if(arr[i] < arr[minIndex]){
                minIndex = i;
            }
        }
        int temp = arr[0];
        arr[0] = arr[maxIndex];
        arr[maxIndex] = temp;
        minIndex = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]<arr[minIndex]){
                minIndex = i;
            }
        }
        temp = arr[arr.length-1];
        arr[arr.length-1] = arr[minIndex];
        arr[minIndex] = temp;
        for(int num:arr){
            System.out.println(num);
        }
        scanner.close();
    }
}
